#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int countDays(int days, vector<vector<int>>& meetings) {
        sort(meetings.begin(), meetings.end());
        int start = 0, end = 0, res = 0;
        for (auto& vec : meetings)
        {
            if (vec[0] > end)
                res += vec[0] - end - 1;
            end = max(end, vec[1]);
        }
        res += days - end;
        return res;
    }
};